using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

namespace HostingDemo
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var collector = new FakeMetricsCollector();
            new HostBuilder()
                .ConfigureAppConfiguration(builder =>
                {
                    builder.AddJsonFile("appsettings.json");
                })
                .ConfigureServices((ctx,service) =>
                {
                    //service.AddHostedService<PerformanceMetricsCollector>();
                    //service.AddSingleton<IHostedService, PerformanceMetricsCollector>();
                    service.AddSingleton<IProcessorMetricsCollector>(collector);
                    service.AddSingleton<IMemoryMetricsCollector>(collector);
                    service.AddSingleton<INetworkMetricsCollector>(collector);

                    service.AddSingleton<IMetricsDeliver, FakeMetricsDeliver>();
                    service.AddHostedService<PerformanceMetricsCollector2>();

                    service.AddOptions().Configure<MetricsCollectorOption>(ctx.Configuration.GetSection("MetricsCollector"));
                })
                .Build().Run();
        }
    }
}
